package com.example.mysqltransaction.service;

import com.example.mysqltransaction.mapper1.UserMapper1;
import com.example.mysqltransaction.mapper2.UserMapper2;
import com.example.mysqltransaction.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @Author: 杨雄杰
 * @Date: 2020/5/28 4:29 下午
 */

@Service
public class UserService {

    @Autowired
    private UserMapper1 userMapper1;

    @Autowired
    private UserMapper2 userMapper2;

    @Transactional
    public void addUser(User user) throws Exception {
        userMapper1.addUser(user.getName(), user.getAge());
        userMapper2.addUser(user.getName(), user.getAge());
    }
}